using Microsoft.AspNetCore.Mvc;

namespace webapi01.Controllers;

[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
    private static readonly string[] Summaries = new[]
    {
    "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

    private readonly ILogger<WeatherForecastController> _logger;

    public WeatherForecastController(ILogger<WeatherForecastController> logger)
    {
        _logger = logger;
    }

    [HttpGet]
    public async Task Get()
    {
        await M01();
    }


    static async Task M01()
    {
        using var client = new HttpClient();
        var filename = @"f:\temp\abc.pdf";
        var url = "http://192.168.1.81:8765/ThirdPartyApi/ThirdPart/UploadFileV2/ACT20C0800009";
        var appReferer = "http://192.168.1.81:8765";
        var appSecret = "e6ccef4c44f6423a97ae940596c02912";
        var appId = "eac59e3c60d345fcb9fde19672a6d6dd";
        var method = "post";
        client.DefaultRequestHeaders.Add("HiAuthAppKey", appId);
        client.DefaultRequestHeaders.Add("HiAuthAppVersion", "V2.0");
        client.DefaultRequestHeaders.Add("HiAuthAppReferer", appReferer);
        var sign = GenerateSignature(url, method, "V2.0", appReferer, appSecret, filename, "", true);
        client.DefaultRequestHeaders.Add("HiAuthAppSignature", sign);
        var content = new StreamContent(System.IO.File.OpenRead(filename));
        try
        {
            var response = await client.PostAsync(url, content);
            response.EnsureSuccessStatusCode();
            var readResult = await response.Content.ReadAsStringAsync();
            Console.WriteLine(readResult);
        }
        catch (Exception exp)
        {
            Console.WriteLine(exp.ToString());
        }
        finally
        {
            content.Dispose();
        }
    }

    static string GenerateSignature(
        string url,
        string method,
        string version,
        string referer,
        string appSecurity,
        string filePath, string postBody, bool isUploadFile = false
    )
    {
        return "";
    }
}